package com.zzc.controller;

import com.zzc.common.JsonResult;
import com.zzc.common.TableResult;
import com.zzc.mapper.RoleMapper;
import com.zzc.pojo.Menu;
import com.zzc.pojo.Role;
import com.zzc.service.MenuService;
import com.zzc.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhouzhicheng
 * @version 1.0  2020/12/30
 */
@RequestMapping("/sys/role")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;
    @RequestMapping("/table")
    public TableResult getRoleList( String name,Integer page, Integer limit){
        return roleService.getRoleList(name,page,limit);
    }
    @RequestMapping("/add")
    public JsonResult addUser(Role role){
        return roleService.insertRole(role);
    }
    @RequestMapping("/update")
    public JsonResult updateUser(Role role){
        return roleService.updateByPrimaryKeySelective(role);
    }
    @RequestMapping("/role_menu")
    public List<Integer> getUserRole(Integer roleId){
        return roleService.getRoleMenu(roleId);
    }
    @RequestMapping("/menu_tree")
    public List<Menu> getMenus(){
        return roleService.getMenus();
    }
    @RequestMapping("/assign_menu")
    public JsonResult updateUserRole(Integer roleId,Integer[] menuIds){
        return roleService.updateRoleMenu(roleId,menuIds);
    }

}
